package com.flyaudio.xiaopengautopilot.util;

import android.util.Log;

import java.io.File;

public class FileOpenPatch {
    private static final String TAG="FileOpenPatch";
    public interface TaskCallback{
        void run();
    }
    private static final String sdcard_path="/storage/emulated/0/FlyCarMsg";
    public FileOpenPatch(TaskCallback callback){
        this.callback = callback;
        taskThread.start();
    }
    private TaskCallback callback;
    Thread taskThread = new Thread(new Runnable() {
        @Override
        public void run() {
            int count = 20;
            while (true){
                File file = new File(sdcard_path);
                if(file.exists()){
                    callback.run();
                    break;
                }else{
                    try {
                        Log.d(TAG, "run: " + sdcard_path + " NO EXISTS");
                        Thread.sleep(100);
                        if(count-- < 0){
                            file.mkdir();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    });
}
